import { FileSystemIconLoader } from '@iconify/utils/lib/loader/node-loaders'
import { presetUni } from '@uni-helper/unocss-preset-uni'
import {
  defineConfig,
  presetIcons,
  transformerDirectives,
  transformerVariantGroup,
} from 'unocss'

export default defineConfig({
  presets: [
    presetUni({
      attributify: {
        ignoreAttributes: [],
        prefixedOnly: true,
        // 组件库的属性命名和 unocss 冲突，添加前缀，see: https://github.com/uni-helper/unocss-preset-uni#attributify
        prefix: 'us-',
      },
    }),
    presetIcons({
      warn: true,
      extraProperties: {
        'display': 'inline-block',
        'vertical-align': 'middle',
      },
      prefix: ['usvg-'],
      collections: {
        custom: FileSystemIconLoader('./src/static/svgs', svg => svg.replace(/(<svg.*?width=)"(.*?)"/, '$1"1em"').replace(/(<svg.*?height=)"(.*?)"/, '$1"1em"')),
      },
    }),
  ],
  transformers: [
    transformerDirectives(),
    transformerVariantGroup(),
  ],
})
